package com.hxzy.util;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.ConvertUtilsBean;
import org.apache.commons.beanutils.PropertyUtilsBean;

import java.time.LocalDateTime;

/**
 * @author nick
 * @description
 * @date create in 2020/9/11
 */
public class Populater {
    private BeanUtilsBean beanUtilsBean;
    private static Populater instance = new Populater();
    public static Populater getInstance() {
        return instance;
    }

    //将自定义的类型转换器注册
    private Populater(){
        //ConvertUtilsBean内部维护了54个默认的类型转换器
        ConvertUtilsBean convertUtilsBean = new ConvertUtilsBean();
        //将自定义的类型转换器注册到ConvertUtilsBean对象
        convertUtilsBean.register(new DateTimeConverter(), LocalDateTime.class);
        //实例化BeanUtilsBean对象，对反射对象t中的属性赋值
        this.beanUtilsBean = new BeanUtilsBean(convertUtilsBean, new PropertyUtilsBean());
    }

    public BeanUtilsBean getBeanUtilsBean() {
        return beanUtilsBean;
    }

    public void setBeanUtilsBean(BeanUtilsBean beanUtilsBean) {
        this.beanUtilsBean = beanUtilsBean;
    }
}
